var common_image = {};

common_image.checkAuth = function() {
    return requestScreenCapture()
}

common_image.findImage = function(template, callback) {
    if (!requestScreenCapture()) {
        toast("请求截图失败");
        callback(None);
        return None
    }
    var p = images.findImage(captureScreen(), template, {});
    callback(p);
    return p
}

common_image.findImageAndClick = function(img_path) {
    var template = images.read(files.path(img_path));
    if (!template) {
        console.log("未找到图片模板");
        return false
    }
    var p = common_image.findImage(template, function(p) {
        if (p) {
            console.log("找到图片");
        } else {
            console.log("未找到图片");
        }
    })
    if (p) {
        let xx = random(p.x, p.x + template.getWidth())
        let yy = random(p.y, p.y + template.getWidth())
        click(xx, yy)
    }
    return p
}


module.exports = common_image